import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		cartList:uni.getStorageSync("cartList")||[]
	},
	mutations: {
		setCartList(state, cartList) {
			uni.setStorageSync("cartList",cartList)
		}
	},
	getters:{
		onTotPrice(state){
			let price=0
			state.cartList.forEach(item=>{
				if(item.checkbox){
					price+=item.nums*item.goods_price
				}
			})
			return price
		},
		oncheckBoxNum(state){
			let num=0
			state.cartList.forEach(item=>{
				if(item.checkbox){
					num+=item.nums
				}
			})
			return num
		},
		onCartList(state){
			console.log(state);
			return state.cartList.filter(item=>item.checkbox)
		}
	}
})

export default store